<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>原型对象</title>
</head>

<body>
  <script>
    function Dog(type, age, color) {
      // 1、new会创建
      // var obj = {}
      // 2、this -> obj

      this.type = type;
      this.age = age;
      this.color = color;
      this.say = function () {
        console.log(this.age)
      }
      // 3、new 会返回这个obj
      // return obj
    }

    // prototype 原型对象  给实例化对象提供共有的属性和方法
    Dog.prototype.speak = function () {
      console.log('我是一只狗子')
    }

    Dog.prototype.animal = '修狗'

    let Dog1 = new Dog('柯基', '2', 'green')

    Dog1.say()
    Dog1.speak()
    console.log(Dog1.animal)

    let Dog2 = new Dog('秋田', '3', 'red')

    Dog2.say()
    Dog2.speak()
    console.log(Dog2.animal)

    // speak 是原型对象上的共有的方法
    console.log(Dog1.speak == Dog2.speak)
    // say方法 每个new出来的对象就会重新创建一个say方法
    console.log(Dog1.say == Dog2.say)

    console.log(Dog1.constructor)
    // constructor 就是构造函数
    
    
  </script>
</body>

</html>